import pygame
from food import Food
from snake import Snake


class Screen:
    screen_x = 0
    screen_y = 0
    grid_size = 0

    def __init__(self, screen_x, screen_y, grid_size) -> None:
        self.screen_x = screen_x
        self.screen_y = screen_y
        self.grid_size = grid_size
        self.add_snake()
        self.random_add_food()

    def get_screen_size(self):
        return self.screen_x, self.screen_y

    def add_snake(self):
        snake = Snake(self.screen_x, self.screen_y, self.grid_size)
        self.snake = snake

    def eat_food(self):
        snake = self.snake()
        snake = snake.grow_up()
        self.snake = snake
        self.random_add_food(self)

    def random_add_food(self):
        snake = self.snake
        snake_grids = snake.get_grids()
        screen_x, screen_y = self.get_screen_size()
        random_food = Food.random_food(screen_x, screen_y, self.grid_size, snake_grids)
        self.food = random_food

    def draw(self, pygame_screen):
        snake_grids = self.snake.get_draw_grids()
        food_grid = self.food.get_draw_grid()
        for snake_grid in snake_grids:
            pygame.draw.circle(pygame_screen, color = (0,255,0), center = snake_grid, radius = self.grid_size / 2)

        pygame.draw.circle(pygame_screen, color = (0,0,0), center = food_grid, radius = self.grid_size / 2)

    def chk_eat(self):
        snake_grids = self.snake.get_grids()
        food_grid = self.food.get_grid()
        if food_grid in snake_grids:
            self.snake.eat()
            self.remove_food()
            self.random_add_food()

    def remove_food(self):
        Food = self.food
        del Food
        self.food = None




    